package shortcuthelper;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import entry.Entry;

public class ShortcutHelperTest1 {
	
	ShortcutHelper shortcuthelper = new ShortcutHelper();
	Entry entry = new Entry();
	
	
	public void setEntry(String abbr){
		entry.setAbbr(abbr);
		entry.setExtension("Rozw");
		entry.setDescription("Opis");
	}

	@Test
	public void getList() {
		assertNotNull(shortcuthelper.getList());
	}
	
	@Test
	public void setImporter() {
		shortcuthelper.setImporter(new Importer(){

			@Override
			public List<Entry> importEntries(File source) throws IOException {
				// TODO Auto-generated method stub
				return new ArrayList<Entry>();
			}
			
		});
		
		assertNotNull(shortcuthelper.importer);
		shortcuthelper.importList(null);
		assertNotNull(shortcuthelper.getList());
		assertEquals(0, shortcuthelper.getList().size());
	}
	
	@Test
	public void setExporter() {
		shortcuthelper.setExporter(new Exporter(){

			@Override
			public void export(List<Entry> list, File target)
					throws IOException {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		assertNotNull(shortcuthelper.exporter);
		shortcuthelper.exportList(null);
	}
	
	@Test
	public void addToList(){
		setEntry("AAA");
		shortcuthelper.addToList(entry);
		assertEquals("AAA",shortcuthelper.list.get(0).getAbbr());
		assertEquals("Rozw",shortcuthelper.list.get(0).getExtension());
		assertEquals("Opis",shortcuthelper.list.get(0).getDescription());
		
	}
	
	@Test
	public void removeFromList(){
		setEntry("AAA");
		shortcuthelper.addToList(entry);
		assertTrue(!shortcuthelper.list.isEmpty());
		shortcuthelper.removeFromList(entry);
		assertTrue(shortcuthelper.list.isEmpty());
	}
	
	@Test
	public void editOnList(){
		setEntry("AAA");
		shortcuthelper.addToList(entry);
		assertEquals("AAA",shortcuthelper.list.get(0).getAbbr());
		assertEquals("Rozw",shortcuthelper.list.get(0).getExtension());
		assertEquals("Opis",shortcuthelper.list.get(0).getDescription());
		int index = shortcuthelper.list.indexOf(entry);
		setEntry("BBB");
		shortcuthelper.addToList(index,entry);
		assertEquals("BBB",shortcuthelper.list.get(0).getAbbr());
		assertEquals("Rozw",shortcuthelper.list.get(0).getExtension());
		assertEquals("Opis",shortcuthelper.list.get(0).getDescription());
	}

}
